package com.aruba.girlanime;

import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Matrix;

/**
 * Created by tuoniu on 2018/1/18.
 */

public class BitmapUtils {

    public static Bitmap mergebitmap(Bitmap backBitmap, Bitmap picBitmap, Bitmap logoBitmap) {

        int width = backBitmap.getWidth();
        int height = backBitmap.getHeight();
        // 得到新的图片
        Bitmap bitmap3 = Bitmap.createBitmap(backBitmap.getWidth(), backBitmap.getHeight(), Bitmap.Config.RGB_565);
        Canvas canvas = new Canvas(bitmap3);
        canvas.drawColor(Color.WHITE);
        canvas.drawBitmap(backBitmap, 0, 0, null);

        int picWidth = picBitmap.getWidth();

        float scaleRatio = (width * 2 / 3) / (float) picWidth;
        Matrix matrix = new Matrix();
        matrix.postScale(scaleRatio, scaleRatio);
        //长和宽放大缩小的比例
        Bitmap resizeBmp = Bitmap.createBitmap(picBitmap, 0, 0, picBitmap.getWidth(), picBitmap.getHeight(), matrix, true);

        int picLeft = (width - resizeBmp.getWidth()) / 2;
        int picTop = (height - resizeBmp.getHeight()) / 2;
        canvas.drawBitmap(resizeBmp, picLeft > 0 ? picLeft : 0, picTop > 0 ? picTop : 0, null);

        canvas.drawBitmap(logoBitmap, width - logoBitmap.getWidth() - (width - resizeBmp.getWidth()) / 2,
                height - logoBitmap.getHeight() - (height - resizeBmp.getHeight()) / 2, null);

        return bitmap3;
    }

}
